#pragma once

#include "IDT.h"

#define MAX_GDT_ENTRIES	256

typedef struct
{
	WORD  Limit;
	DWORD Base;
} GDT_OBJ, *PGDT_OBJ;

class GDT
{
private :
	bool m_isActivated;

	IDT	*m_pIdt;

	GDT_OBJ m_gdt;
	QWORD	m_entries[MAX_GDT_ENTRIES];

	WORD	m_lastEntryId;

	//WORD m_cs;
	WORD m_ds;
	WORD m_es;
	//WORD m_ss;
	WORD m_gs;
	WORD m_fs;
private:
	static QWORD CreateEntry(DWORD base, DWORD limit, WORD flag);

public:
	GDT(void);
	~GDT(void);

	static GDT Attach();

	void AttachIDT(IDT* pIdt)
	{
		m_pIdt = pIdt;
	}

	//void AssumeCS(WORD sel);
	void AssumeDS(WORD sel);
	void AssumeES(WORD sel);
	//void AssumeSS(WORD sel);

	void AssumeFS(WORD sel);
	void AssumeGS(WORD sel);

	void Activate();

	WORD AddCodeEntry(DWORD base, DWORD limit, BYTE ring);
	WORD AddDataEntry(DWORD base, DWORD limit, bool isReadOnly, BYTE ring);
};

